package com.longxiao.entity;

import java.util.Date;

public class ClientVersion implements Comparable<ClientVersion>{
    private Integer id;

    private String version;

    private String channels;

    private Byte clientType;

    private String osType;

    private String osLowVersion;

    private String osHighVersion;

    private String downloadUrl;

    private Boolean beforceupdate;

    private Boolean status;

    private String remark;

    private Date createdTime;

    private Date modifiedTime;

    @Override
    public int compareTo(ClientVersion o) {
        if(this.getVersion() == null || o == null || o.getVersion() == null){
            return 0;
        }
        String verson1 = this.getVersion();
        String verson2 = o.getVersion();
        if(verson1.endsWith(verson2)){
            return 0;
        }
        String[] vs1 = verson1.split("\\.");
        String[] vs2 = verson2.split("\\.");
        int index = 0;
        for(String v1 : vs1){
            String v2 = vs2[index++];
            int vn1 = Integer.parseInt(v1);
            int vn2 = Integer.parseInt(v2);
            if(vn1 > vn2){
                return 1;
            }
            if(vn1 < vn2){
                return -1;
            }
        }
        return 0;
    }

    /*
    *是否高于目标版本
    */
    public boolean beHigher(String targetVersion){
        ClientVersion clientVersion = new ClientVersion();
        clientVersion.setVersion(targetVersion);
        int res = this.compareTo(clientVersion);
        return res > 0;
    }

    @Override
    public String toString() {
        return "ClientVersion{" +
                "id=" + id +
                ", version='" + version + '\'' +
                ", channels='" + channels + '\'' +
                ", osType='" + osType + '\'' +
                ", osLowVersion='" + osLowVersion + '\'' +
                ", osHighVersion='" + osHighVersion + '\'' +
                ", downloadUrl='" + downloadUrl + '\'' +
                ", beforceupdate=" + beforceupdate +
                ", status=" + status +
                ", remark='" + remark + '\'' +
                ", createdTime=" + createdTime +
                ", modifiedTime=" + modifiedTime +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version == null ? null : version.trim();
    }

    public String getChannels() {
        return channels;
    }

    public void setChannels(String channels) {
        this.channels = channels == null ? null : channels.trim();
    }

    public Byte getClientType() {
        return clientType;
    }

    public void setClientType(Byte clientType) {
        this.clientType = clientType;
    }

    public String getOsType() {
        return osType;
    }

    public void setOsType(String osType) {
        this.osType = osType == null ? null : osType.trim();
    }

    public String getOsLowVersion() {
        return osLowVersion;
    }

    public void setOsLowVersion(String osLowVersion) {
        this.osLowVersion = osLowVersion == null ? null : osLowVersion.trim();
    }

    public String getOsHighVersion() {
        return osHighVersion;
    }

    public void setOsHighVersion(String osHighVersion) {
        this.osHighVersion = osHighVersion == null ? null : osHighVersion.trim();
    }

    public String getDownloadUrl() {
        return downloadUrl;
    }

    public void setDownloadUrl(String downloadUrl) {
        this.downloadUrl = downloadUrl == null ? null : downloadUrl.trim();
    }

    public Boolean getBeforceupdate() {
        return beforceupdate;
    }

    public void setBeforceupdate(Boolean beforceupdate) {
        this.beforceupdate = beforceupdate;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark == null ? null : remark.trim();
    }

    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }
}